import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

// 路由表
const routes = [
  // 配置登录页面路由
  {
    path: '/login',
    name: 'login',
    // 只有访问路径的时候才会执行箭头函数，不访问不调用
    component: () => import('@/views/login')
  },
  // 配置页面组件布局路由
  {
    path: '/',
    name: '',
    component: () => import('@/views/layout'),
    // 二级路由
    children: [
      {
        // 默认子路由
        path: '',
        name: 'home',
        component: () => import('@/views/home')
      },
      {
        path: 'qa',
        name: 'qa',
        component: () => import('@/views/qa')
      },
      {
        path: 'video',
        name: 'video',
        component: () => import('@/views/video')
      },
      {
        path: 'my',
        name: 'my',
        component: () => import('@/views/my')
      }
    ]
  },
  // 把搜索页面的路由配置到根组件路由（一级路由）
  {
    path: '/search',
    name: 'search',
    component: () => import('@/views/search')
  },
  {
    path: '/article/:articleId',
    name: 'article',
    component: () => import('@/views/article'),
    // 开启 props 传参，就是把路由参数映射到组件的 props 中
    props: true
  },
  // 用户信息管理界面
  {
    path: '/user/profile',
    name: 'user-profile',
    component: () => import('@/views/user-profile')
  }
]

const router = new VueRouter({
  routes
})

export default router
